<script language="javascript" type="text/javascript">
    $(window).scroll(
    function()
    {
        scrollTop = $(window).scrollTop();
        docHeight = getDocHeight();
        winHeight = getWinHeight();
        scrolltop20 = Math.round((getDocHeight() - getWinHeight())*0.9);
        result = getDocHeight() - getWinHeight();
		
        console.log('Top Scroll: '+ scrollTop +' || Win Height: '+ winHeight +' || Doc Height: '+ docHeight+' || scrolltop20: '+scrolltop20+' || result :'+ result );
	
        if($(window).scrollTop() >= scrolltop20)
        {
            if(killScroll == false) 
            {
                killScroll = true;
				
                $('#loading').show();
                $('#loadding-text').show();			
                $('#loading').html('<img src="images/loading.gif" alt="" width="150" height="13" />');

                if($("li:last").data('ctype') == 'news')
                {
                    lastPostFunc('news');
                }
                setTimeout(function(){killScroll = false},500);	
            }
        }
    }
); 


    function searchNews()
    {
        if($('#news_search').val() == '')
        {	
            $('#newsAlert').popup('open');
            setTimeout(function(){$('#newsAlert').popup('close'); $('#news_search').focus()},1000);
        }
        else
        {
            $('#fromSearchNews').submit();
        }
    }

</script> 

<!-- Start of news page -->        
<div data-role="page" id="news">
    <div data-role="header"> 
        <h1>ข่าวสาร</h1>
        <a rel="external" id="link_web" href="?q=home" data-icon="back" data-iconpos="right" data-transition="flip">กลับ</a> 
        <a id="link_from_news_search" href="#from_NewsSearch" data-icon="search" data-iconpos="right" data-transition="slidedown" data-rel="dialog">ค้นหา</a>       
    </div><!-- /header -->

    <div data-role="content">	

        <ul data-role="listview">
            <li data-role="list-divider" id="listDivider_step">
                <a rel="external" href="?q=home">หน้าแรก</a>&nbsp;&nbsp;>>&nbsp;&nbsp;<a rel="external" href="?q=news">ข่าวสาร</a>
            </li>  
            <?php
//$showData = mysql_query('SELECT id, name FROM news  ORDER BY id DESC LIMIT 20 ') or die(mysql_query());	

            $res = $db->select_query('SELECT * FROM news  ORDER BY id DESC LIMIT 20');
            while($arr = $db->fetch($res))
            {
                $countReply = $db->num_rows('news_reply', 'reply_id', 'news_id = ' . $arr['id'] . '');
                ?>
                <li data-ctype="news" id="news_<?php echo $arr['id']; ?>" last_id="<?php echo $arr['id']; ?>">
                    <a rel="external" href="?q=newsDetail&newsId=<?php echo $arr['id']; ?>">
                        <img src="<?php echo $arr['tn_part']; ?>" alt="" width="80" height="80" />
                        <h3><?php echo $arr['name']; ?></h3>
                        <p><?php echo $arr['title'];?></p>
                        <span class="ui-li-count ui-btn-up-c ui-btn-corner-all"><?php echo $countReply; ?></span>
                    </a> 
                </li>

                <?php
            }
            ?>
        </ul> 
        <div id="loadding-text" style="clear:both;" align="center">&nbsp;</div>       
        <div id="loading" align="center"></div>       
    </div><!-- /content -->

    <div data-role="footer" >
        <h4>Version 1.0 Beta</h4>
        <a id="link_web" href="http://www.mocyc.com" data-icon="refresh" data-iconpos="right" class="ui-btn-right">แบบปกติ</a>

    </div><!-- /footer -->
</div><!-- /page -->

<!-- From NewsSearch -->
<div data-role="page" id="from_NewsSearch">
    <div data-role="header">
        <h1>ค้นหา</h1>
    </div>

    <div data-role="content">
        <form id="fromSearchNews" name="fromSearchNews" method="get" data-transition="fade" data-ajax="false">
            <input type="hidden" name="q" value="newsSearch" />
            คำค้นหา
            <input  type="search" name="news_search" id="news_search" value=""  />    
            หมวดหมู่
            <select name="news_type" id="news_type">
                <option value="0" selected="selected">- ไม่ระบุ -</option>
                <option value="1">ข่าวสารวงการมอเตอร์ไซค์</option>
                <option value="2">ข่าวสารวงการยานยนต์</option>
                <option value="3">ข่าวสารกิจกรรม</option>
            </select>     

            <label>&nbsp;</label><br /> 
            <input id="search" name="search" type="button" value="ค้นหา" onclick="searchNews();" />
        </form>

        <div data-role="popup" id="newsAlert">
            <p>กรุณาระบุ "คำค้นหา" ที่ต้องการ<p>
        </div> 

    </div>

</div>
<!-- End From NewsSearch -->